package cn.hoichun.news.Service.Impl;

import cn.hoichun.news.Domain.View;
import cn.hoichun.news.Mapper.ScoreMapper;
import cn.hoichun.news.Service.IScoreService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Hoichun
 */
@Service
public class ScoreServiceImpl implements IScoreService {
    private final ScoreMapper scoreMapper;

    public ScoreServiceImpl(ScoreMapper scoreMapper) {
        this.scoreMapper = scoreMapper;
    }

    @Override
    public boolean scoreCheck(int userId, int articleId) {
        return scoreMapper.getScore(userId, articleId) != null;
    }

    @Override
    public View getScore(int userId, int articleId) {
        if (scoreCheck(userId, articleId)) {
            return scoreMapper.getScore(userId, articleId);
        } else {
            return new View(userId, articleId, -1, -1, new Date());
        }
    }

    @Override
    public void addScore(int userId, int articleId, int interest, int quality) {
        scoreMapper.insertScore(userId, articleId, interest, quality, new Date());
    }

    @Override
    public List<Integer> getArticlesByUserId(int userId) {
        return scoreMapper.selectArticleByUserId(userId);
    }

}
